<?php 
namespace Admin\Controller;
/**
 * 后台用户控制器
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class AttrController extends AdminController{
	public function index(){
		$name       =   I('name');
        $map['status']  =   array('egt',0);
        if(is_numeric($name)){
            $map['id|name']=   array(intval($name),array('like','%'.$name.'%'),'_multi'=>true);
        }else{
            $map['name']    =   array('like', '%'.(string)$name.'%');
        }

        $list   = $this->lists('attr', $map);
        $goods = M('goods')->getField('id,name');
        foreach ($list as  $k=>$v) {
            $list[$k]['gname'] = $goods[$list[$k]['gid']];
        }
        int_to_string($list);      
        $this->assign('list', $list);
        $this->meta_title = '属性信息';
        $this->display();
	}
	public function add(){
		if (IS_POST) {
			$add=D('Attr');
			$res=$add->create();
			if ($res) {
                if ($add->add()) {
                    $this->success('添加成功',U('index'));
                }else{
                    $this->error('添加失败',U('add'));
                }
            }else{
                $this->error($add->getError());
            }
		}else{
			$id=I('get.id');
			$res=M('goods')->where(array('id'=>$id))->find();
			// var_dump($res);die;
			$this->assign('res',$res);

			$this->display();
		}
		
	}
	
} 
?>